直接读取ttc、oft、ttf格式的字库,显示出来。本例字库在bin文件夹里面,字库网上很多,自行下载。
static class NativeMethods{const string GDI32 = "gdi32.dll";const string USER32 = "user32.dll";struct Rect{public long Left, Top, Right, Bottom;public Rect (Rectangle rect) {this.Left = rect.Left;this.Top = rect.Top;this.Right = rect.Right;this.Bottom = rect.Bottom;}}static uint ToGdiColor (Color color) {return (uint)(color.R | color.G << 8 | color.B << 16);}[DllImport (GDI32)]internal static extern IntPtr CreateFont (int nHeight,int nWidth,int nEscapement,int nOrientation,int fnWeight,uint fdwItalic,uint fdwUnderline,uint fdwStrikeOut,uint fdwCharSet,uint fdwOutputPrecision,uint fdwClipPrecision,uint fdwQuality,uint fdwPitchAndFamily,string lpszFace);[DllImport (GDI32)]internal static extern IntPtr SelectObject (HandleRef hdc, IntPtr obj);[DllImport (GDI32)]internal static extern bool DeleteObject (HandleRef obj);[DllImport (USER32, CharSet = CharSet.Auto)]static extern int DrawText (HandleRef hDC, string lpchText, int nCount, ref Rect lpRect, uint uFormat);internal static int DrawText (HandleRef hDC, string text, Rectangle rect, uint format) {var r = new Rect (rect);return DrawText (hDC, text, text.Length, ref r, format);}[DllImport (GDI32)]static extern uint SetTextColor (HandleRef hdc, uint crColor);internal static uint SetTextColor (HandleRef hdc, Color color) {return SetTextColor (hdc, ToGdiColor (color));}[DllImport (GDI32)]internal static extern uint SetBkMode (HandleRef hdc, int mode);}
评论